<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<%@ include file="/commons/messages.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>新增住房信息</title>
<link href="${ctx}/styles/public.css" rel="stylesheet" type="text/css">
<link href="${ctx}/styles/listTable.css" rel="stylesheet" type="text/css">
<link href="${ctx}/styles/aux_window.css" rel="stylesheet" type="text/css">

<script language="JavaScript" type="text/javascript" src="${ctx}/scripts/public.js"></script>
<script language="JavaScript" type="text/javascript" src="${ctx}/scripts/show.js"></script>
<script language="JavaScript" type="text/javascript" src="${ctx}/scripts/div/common.js"></script>
<script language="JavaScript" type="text/javascript" src="${ctx}/scripts/common.js"></script>

<script language="JavaScript" type="text/javascript" src="${ctx}/pages/com/ce/pms/customer/tenement.js"></script>
<%@ include file="/commons/validation.jsp" %>

<script language="JavaScript"  src="${ctx}/scripts/ajaxException.js"></script>

<script type="text/javascript">
	var house = null;  //房屋相关操作对象
	var bank = null; //银行相关操作

	function openSelectHouse(){
		house.openSelectHouse("houseChooseFrame");
	}
	function setHouseInfo(houseId,houseNum){
		document.getElementById("houseId").value = houseId;
		document.getElementById("houseNumber").value = houseNum;
		$('houseNumber').fireEvent("onblur")
	}
	function submitForm(){
			var flag = document.getElementById("ownerHouseForm").fireEvent("onSubmit");
			if(flag){
				var str = $("ownerHouseForm").serialize();
				var action = "${ctx}/customer_ownerAction.do?method=addCustomerHouseCache";
				//当房间处在出盘状态时  银行信息是不可以修改的  所以这里添上其值
				if($('bankAccoutEditMessageDIV').style.display == "inline"){
					str += "&bankId=" + $("bankId").value;
					str += "&bankNumber=" + $("bankNumber").value;
					str += "&accountOwner=" + $("accountOwner").value;
					str += "&contactNumber=" + $("contactNumber").value;
				}
				var myAjax = new Ajax.Request(action,
	                    	{method: 'post',
	                    	 parameters: str,
	                    	 onComplete:function(result){
	                    	 					var obj = result.responseText;
												ajaxSubmitException(obj);
		                    	 				closeFrm();
	                    	 				}
	                    	}
	                    );
            }
	}

	/**
	* 处理房号问题--房号不能为空、房号必须存在、房号和业主列表没有登记过
	*/
	function processHouseNumber(obj){
		house.validateHouseNum(obj.value,setContractNumberAndProperty);
	}

	//设置合同号，产权证号
	function setContractNumberAndProperty(){
		var url = "${ctx}/customer_ownerAction.do?method=loadHouseContractNumberAndPropertyNo";
		var parm = "houseNumber=" +  document.getElementById('houseNumber').value;
		new Ajax.Request(url,
            {method: 'post', parameters: parm, onComplete: function(result){
            			var parms=eval('(' + result.responseText + ')');
            			$('houseId').value = parms.houseIdStr;
						$('houseContractNumber').value = parms.houseContractNumber;
						$('housePropertyNo').value = parms.housePropertyNo;

						$('bankName').value = parms.bankName;
						//填充各字段
						bank.fill(parms.bankId,parms.bankNumber,parms.accountOwner,parms.contactNumber);
						//设置状态
						//parms.isIn ture时表示不存在未回盘的数据,false标识存在未回盘的数据,在这里只要存在未回盘的,则帐号不能修改
						var flag = eval(parms.isIn);//帐号是否已出盘标识,ture表示没出盘记录,false表示有出盘记录
						if(flag){//没有出盘记录,判断银行名称是否有值,如果有值,则相应输入框可用,否则不可用
							flag = flag && (parms.bankId != null && parms.bankId != "");
							bank.setStatuz(flag);
							$('bankNameSelect').fireEvent("onchange");
							if(!flag){//如果没有值时,需要对银行名称特殊处理下
								$('bankNameSelect').disabled = false;
								$('bankAccoutEditMessageDIV').style.display = "none";
							}
						}else{
							$('bankAccoutEditMessageDIV').style.display = "inline";
							bank.setStatuz(flag);
						}

            }}
            );
	}

	function closeFrm(){
		findFrame("ownerList").reLoadIframe();
		windowClose();
	}

	function setSelectBackName(thiz){
		if(thiz.selectedIndex == 0 ) {
			document.getElementById("bankName").value = "";
			return;
		}
		var opt = thiz.options[thiz.selectedIndex];
		document.getElementById("bankName").value = opt.text;
	}

//*************银行操作对象*****************///
	//参数说明：银行名称下拉框ID,银行帐号ID、开户人ID、合同号ID
	function Bank(bankName,bankNumber,accountOwner,contactNumber){
		var _bank = null;//自身的引用,这样可以引用其他方法

		var _bankNameObj = $(bankName);//银行名称下拉框
		var _bankNumberObj = $(bankNumber);//银行帐号
		var _accountObj = $(accountOwner);//银行帐号
		var _contactObj = $(contactNumber);//合同号

		var _require = "aux_intable_require";//必选样式
		var _notRequire  = "aux_intable_td2";//不必选样式

		this.init = function(abank){
			_bank = abank;
		}
		//填充各框的输入值,银行名称给定一个银行ID,显示对应银行名称
		this.fill = function(bankId,bankNumber,accountOwner,contactNumber){
			_setBankName(bankId);
			_bankNumberObj.value = bankNumber;
			_accountObj.value = accountOwner;
			_contactObj.value = contactNumber;
		}
		//设置各输入东东状态, true代表可用,false代表不可用
		this.setStatuz = function(flag){
			_bankNameObj.disabled = !flag;
			_bankNumberObj.disabled = !flag;
			_accountObj.disabled = !flag;
			_contactObj.disabled = !flag;
		}
		//银行名称下拉框onchange处理事件
		this.bankNameEventHandle = function(flag){
			if(flag){
				_bankNameObj.parentNode.className = _require;

				_bankNumberObj.parentNode.className = _require;
				Validation.changeElmValidate(_bankNumberObj.id,"inputtext required");

				_accountObj.parentNode.className = _require;
				Validation.changeElmValidate(_accountObj.id, "inputtext required");

				_bank.setStatuz(flag);//设置所有的东东可以用
				$('bankAccoutEditMessageDIV').style.display = "none";
			}else{
				_bankNameObj.parentNode.className = _notRequire;
				_bankNumberObj.parentNode.className = _notRequire;
				Validation.changeElmValidate(_bankNumberObj.id, "inputtext");

				_accountObj.parentNode.className = _notRequire;
				Validation.changeElmValidate(_accountObj.id, "inputtext");

				_bank.setStatuz(flag);//先设置所有的不可用,然后把银行名称下拉框设置回来
				_bankNameObj.disabled = false;
			}
		}

	/***********private method*************/
		//设置银行名称下拉框显示相应银行ID的值
		function _setBankName(bankId){
			var options = _bankNameObj.options;
				for(var i = 0; i < options.length; i++){
					if(options[i].value == bankId){
						_bankNameObj.selectedIndex = i;
						break;
					}
				}
		}
		function _setStyleRequired(flag){

		}
	}
	function init(){
		house = new House('houseNumber');
		bank = new Bank('bankNameSelect','bankNumber','accountOwner','contactNumber');
		bank.init(bank);
		//设置银行名称下拉框  onchange 事件
		$('bankNameSelect').onchange = function(){
										setSelectBackName(this);
										bank.bankNameEventHandle(this.selectedIndex != 0);
									}
		$('bankNameSelect').fireEvent("onchange");
	}
</script>
<base target="_self">
</head>

<body onload="init();">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td class="window_head_outBg"><table border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td><img src="${ctx}/images/ico_Advance.gif" width="16" height="16" align="absmiddle"> <span class="window_head_intext">新增住房信息</span></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td class="aux_header_line_1"></td>
  </tr>
  <tr>
    <td class="aux_header_line_2"></td>
  </tr>
  <tr>
    <td class="content"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td class="aux_outtable_color">

        <form id="ownerHouseForm" name="ownerHouseForm" action="" method="post" id="ownerHouseForm" class="required-validate" onsubmit="$('bankNameSelect').disabled=false;">
        <input id="houseId" name="houseId" type="hidden" value="">
        <input id="manageHouseId" name="manageHouseId" type="hidden" value="">
        <input id="bankName" name="bankName" type="hidden" value="">
        <table width="100%" border="0" cellpadding="0" cellspacing="1" class="aux_intable_color">
            <tr>
              <td class="aux_intable_td1">房号：</td>
              <td class="aux_intable_require">
              	<table border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td><input id="houseNumber"
                    		   name="houseNumber"
                    		   type="text"
                    		   class="inputtext required"
                    		   afterInsert="validationSpanImage"
                    		   onblur="processHouseNumber(this);"
                    		   maxlength="36"
                    		   value=""
                    		   size="16"></td>
                    <td width="4">&nbsp;</td>
                    <td>
                    		<a href="#"  onClick="openSelectHouse();" onFocus="this.blur()">
                    				<img src="${ctx}/images/ico_houesno.GIF" alt="请点选查找房号" border="0">
                    		</a>
                    		<span id="validationSpanImage"></span>
                    </td>
                  </tr>
              </table></td>
            </tr>
            <tr>
              <td class="aux_intable_td1">买卖(预售)合同号：</td>
              <td class="aux_intable_td2"><input name="houseContractNumber" maxlength="50" type="text" class="inputtext validate-ajax" relativeId="houseNumber" validateUrl="${ctx}/customer_ownerAction.do?method=validationHousePropertyContractNumber" value="" size="16"></td>
            </tr>
			 <tr>
               <td class="aux_intable_td1">房产证号：</td>
			   <td class="aux_intable_td2"><input name="housePropertyNo" maxlength="36" type="text" class="inputtext validate-ajax" relativeId="houseNumber" validateUrl="${ctx}/customer_ownerAction.do?method=validationHousePropertyContractNumber" value="" size="16" ></td>
		      </tr>
			 <tr>
              <td class="aux_intable_td1">银行名称：</td>
              <div id="Layer1" noWrap=false style="position:absolute; width:360px; height:115px; z-index:1; left: 0px; top: 120px; filter:Alpha(opacity=0)">

				</div>
              <td class="aux_intable_td2">
					<pms:unitedSelect  name="bankId"
										id="bankNameSelect"
										dataList="${banklist}"
										optionLabel="bankName"
										optionValue="keyword"
										onChange="setSelectBackName(this);bank.bankNameEventHandle(this.selectedIndex != 0);"
										selectText="请选择...">
					</pms:unitedSelect>
					<div id="bankAccoutEditMessageDIV" style="display:none">银行帐号正出盘中不能修改</div>
               </td>
             </tr>
			<tr>
              <td class="aux_intable_td1">银行账号：</td>
              <td class="aux_intable_td2"><input id="bankNumber" name="bankNumber" maxlength="25" type="text" class="inputtext" value="" size="16"><span id="bankNumberMessage"></span></td>
            </tr>
			<tr>
              <td class="aux_intable_td1">开户人：</td>
              <td class="aux_intable_td2"><input id="accountOwner" name="accountOwner"  maxlength="32" type="text" class="inputtext" value="" size="16"></td>
            </tr>
			<tr>
			  <td class="aux_intable_td1">合同号：</td>
			  <td class="aux_intable_td2"><input id="contactNumber" name="contactNumber" type="text" class="inputtext" value="" size="16" maxlength="50"></td>
			</tr>
      </tr>
        </table>
        <input type="submit" id="formSubmit" style="display:none">
        </form>
        </td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td class="window_footer"><table border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><table border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td class="buttonOffLeft" id="btn1_21"></td>
              <td class="buttonOffMiddle" id="btn1_22" onClick="submitForm();" onMouseOver="btn_change_over(2)" onMouseOut="btn_change_out(2)" onblur="btn_change(2)"><img src="${ctx}/images/ico_ok.gif" alt="" width="14" height="14" border="0" align="absbottom"> 确 定</td>
              <td class="buttonOffRight" id="btn1_23"></td>
            </tr>
        </table></td>
        <td class="btn_between_space"></td>
        <td><table border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td class="buttonOffLeft" id="btn1_31"></td>
              <td class="buttonOffMiddle" id="btn1_32" onClick="windowClose();" onMouseOver="btn_change_over(3)" onMouseOut="btn_change_out(3)" onblur="btn_change(3)" ><img src="${ctx}/images/ico_cancel.gif" alt="" width="14" height="14" border="0" align="absbottom"> 取 消</td>
              <td class="buttonOffRight" id="btn1_33"></td>
            </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>